﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace MineSweeper.EventManagers
{
    public class UIElementMouseEnterEventManager : WeakEventManager
    {
        private UIElementMouseEnterEventManager() { }

        public static void AddListener(UIElement source, IWeakEventListener listener)
        {
            CurrentManager.ProtectedAddListener(source, listener);
        }

        public static void RemoveListener(UIElement source, IWeakEventListener listener)
        {
            CurrentManager.ProtectedRemoveListener(source, listener);
        }

        protected override void StartListening(object source)
        {
            ((UIElement)source).MouseEnter += new MouseEventHandler(uiElement_MouseEnter);
        }

        protected override void StopListening(object source)
        {
            ((UIElement)source).MouseEnter -= new MouseEventHandler(uiElement_MouseEnter);
        }

        void uiElement_MouseEnter(object sender, MouseEventArgs e)
        {
            base.DeliverEvent(sender, e);
        }

        private static UIElementMouseEnterEventManager CurrentManager
        {
            get
            {
                var managerType = typeof(UIElementMouseEnterEventManager);
                var currentManager = (UIElementMouseEnterEventManager)WeakEventManager.GetCurrentManager(managerType);
                if (currentManager == null)
                {
                    currentManager = new UIElementMouseEnterEventManager();
                    WeakEventManager.SetCurrentManager(managerType, currentManager);
                }
                return currentManager;
            }
        }
    }
}
